package com.nut.spp.api.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nut.spp.common.Result;
import com.nut.spp.entity.SysParam;
import com.nut.spp.service.SysParamService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

@Slf4j
@RestController
@RequestMapping("/admin/param")
public class ParamController {

    @Autowired
    private SysParamService sysParamService;

    @GetMapping(value = "list")
    public Result<IPage<SysParam>> list(@RequestParam(required = false) String name,
                                        @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        return sysParamService.listPage(name, pageNo, pageSize);
    }

    @GetMapping(value = "/{id}")
    public Result<SysParam> detail(@PathVariable Integer id) {
        return sysParamService.getById(id);
    }

    @PostMapping
    public Result add(@RequestBody SysParam brand) {
        return sysParamService.add(brand);
    }

    @DeleteMapping
    public Result delete(@RequestBody Set<Integer> ids) {
        return sysParamService.deleteByIds(ids);
    }

}